<style lang="scss" scoped>
    @import '@/assets/css/index';
    .applyGetMoney{
        padding: 10px;
        @include page();
        .box{
            display: flex;
            flex-direction: column;
            align-items: left;
            background-color: white;
            .money{
                display: flex;
                flex-direction: row;
                .icon{
                    font-size: 4rem;
                    font-weight: bold;
                }
                .text{
                    font-size: 4rem;
                    font-weight: bold;
                }
            }
            
            .btn{
                width: 100%;
                margin-top: 2rem;
            }
        }
    }
</style>
<template>
  <div class="applyGetMoney">
      <BarNav></BarNav>
      <div class="box padding-all-l">
            <div>提现金额</div>
            <div class="money margT-l">
                <span class="icon">￥</span>
                <div class="text">
                    <van-field v-model="num" placeholder="请输入提现金额" />
                </div>
            </div>
            <!-- {{promoterItema}} -->
            <div class="color-m margT-m line-height-m">当前可提现余额{{promoterItema.commission_out}}元,最小提现金额为 0.01 元</div>
            <a class="all line-height-m" :style="{color:$store.getters.getMasterColor}" @click="getAll">全部提现</a>
            <div class="btn">
                <van-button @click="withdrawalSave" :color="$store.getters.getMasterColor" round block>提交申请</van-button>
            </div>
      </div>
  </div>
</template>

<script>
import { Button, Cell, Field, Dialog, Toast } from 'vant'
import {myMixins} from "@/assets/js/mixins.js"
import BarNav from "@/components/BarNav"
import { mapState } from 'vuex'
export default {
	mixins:[myMixins],
    name: 'ApplyGetMoney',
    components: {
        [Button.name]: Button,
        [Cell.name]: Cell,
        [Field.name]: Field,
        [Dialog.name]: Dialog,
        BarNav
    },
    data () {
        return {
            myInfo:'',
            num:'',
            userInfo:'',
            minimum:''
        }
    },
    computed: {
        ...mapState(["promoterItema"])
    },
    mounted () {
        this.myInfo = this.$store.state.myInfo
        this.userInfo = this.$store.state.userInfo
        this.minimum = this.$store.state.minimum || localStorage.getItem("MININUM")
        if(!this.userInfo||!this.myInfo){
            this.$router.replace('/my')
            return
        }
    },
    methods: {
        withdrawalSave() {
            if(this.num<this.minimum){
                Dialog.alert({
                    title: '系统提示',
                    message: `提现最小金额为: 0.01 元`,
                }).then(() => {
                    return
                });
                return
            }
            let params = {
                promoter_id: this.promoterItema.id,
                money: this.num
            }
            this.$request.withdrawalSave(params).then(res=>{
                if(res.ret == 200) {
                     Dialog.alert({
                    title: '系统提示',
                    message: `提现申请成功，请等待客服审核`,
                }).then(() => {
                    this.$router.replace('/promoter')
                });
                } else {
                    Toast(res.msg.slice(5))
                }
            })
        },
        getAll() {
            this.num = this.promoterItema.commission_out
        }
    }
}
</script>